package com.ctrl.riveradministrator.mvp.view.activity.suggest;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Message;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.ctrl.riveradministrator.R;
import com.ctrl.riveradministrator.base.BaseActivity;
import com.ctrl.riveradministrator.base.BasePresenter;
import com.ctrl.riveradministrator.mvp.model.Suggest;
import com.ctrl.riveradministrator.mvp.presenter.SuggestPresenter;
import com.luck.picture.lib.tools.ToastManage;

import java.util.List;

public class SuggestUploadActivity extends BaseActivity<SuggestPresenter> implements SuggestView {

    private Toolbar toolbar;
    private TextView titleTv;
    private ImageView leftMenu;

    private EditText suggestM,suggestD;
    private Button submitBtn;
    private Suggest suggest;

    @Override
    protected void initParams(Bundle parms) {

    }

    @Override
    protected int bindLayout() {
        return R.layout.activity_suggest_upload;
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void initView(View view) {
        toolbar = (Toolbar) $(R.id.toolbar);
        titleTv = (TextView) $(R.id.title_tv);
        leftMenu = (ImageView) $(R.id.left_iv);
        suggestM = (EditText) $(R.id.suggest_manager);
        suggestD = (EditText) $(R.id.content);
        submitBtn = (Button) $(R.id.submit);

        /*
         * 设置toolbar
         * */
        toolbar.setTitleTextColor(Color.WHITE);
        toolbar.setTitle("");
        titleTv.setText("上报建言献策");
        leftMenu.setBackground(getDrawable(R.drawable.ic_chevron_left_24dp));
    }

    @Override
    protected void doBusiness(Context mContext) {

    }

    @Override
    protected void widgetClick(View view) {
        switch (view.getId()) {
            case R.id.left_iv:
                finish();
                break;
            case R.id.submit:
                mPresenter.uploadSuggests(suggestM.getText().toString(),suggestD.getText().toString());
                break;
        }
    }

    @Override
    protected void setListener() {
        leftMenu.setOnClickListener(this);
        submitBtn.setOnClickListener(this);
    }

    @Override
    public void handleMessage(Message message, int what) {

    }

    @Override
    protected SuggestPresenter createPresenter() {
        return new SuggestPresenter(this);
    }

    @Override
    public void showMessage(List<Suggest> suggests) {
        Toast.makeText(this,"上传成功",Toast.LENGTH_LONG).show();
    }

    @Override
    public void showError(String msg) {
        Toast.makeText(this,"上传失败",Toast.LENGTH_LONG).show();
    }
}
